#include "LoginService.h"
#include "LoginSession.h"
#include "xLog.h"
LoginService::LoginService()
             : xNetService{g_server_addr,g_server_port}
             , m_netThread(nullptr)
             , m_gameThread(nullptr)
{
}

bool LoginService::Init()
{
    if(!xNetService::Init())
    {
        return false;
    }
    m_netThread = new xNetThread();
    m_netThread->Start();

    m_gameThread = new LoginRunThread();
    m_gameThread->Start(); 

    return true;
}

bool LoginService::NewTCPTask(xSocket* socket)
{
    LoginSession* session = new LoginSession(socket);
    m_netThread->Push(session);
    return true;
}

void LoginService::Finish()
{
    xNetService::Finish();
    if(m_gameThread)
    {
        m_gameThread->Finish();
        DELETE(m_gameThread);
    }
    if(m_netThread)
    {
        m_netThread->Finish();
        DELETE(m_netThread);
    }
}